/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.easyedu.dictionary.editor.actions;

import eu.easyedu.dictionary.editor.DefaultDictionaryWindowTopComponent;
import javax.swing.JEditorPane;
import org.openide.cookies.EditorCookie;
import org.openide.nodes.Node;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CookieAction;

public final class TranslateWordAction extends CookieAction {

    private final static long serialVersionUID = 1L;
    private final static String DEFAULT_BUNDLE = "eu/easyedu/dictionary/editor/resources/Bundle";

    protected void performAction(Node[] activatedNodes) {
        EditorCookie editorCookie = activatedNodes[0].getLookup().lookup(EditorCookie.class);
        String initSearchText = null;
        if (editorCookie != null) {
            JEditorPane[] openedPanes = editorCookie.getOpenedPanes();
            if (openedPanes != null) {
                initSearchText = org.netbeans.editor.Utilities.getSelectionOrIdentifier(openedPanes[0]);
                DefaultDictionaryWindowTopComponent win = DefaultDictionaryWindowTopComponent.findInstance();
                win.open();
                win.requestActive();
                win.setSearchText(initSearchText);
            }
        }
    }

    protected int mode() {
        return CookieAction.MODE_EXACTLY_ONE;
    }

    public String getName() {
        return NbBundle.getBundle(DEFAULT_BUNDLE).getString("CTL_TranslateWordAction");
    }

    protected Class[] cookieClasses() {
        return new Class[]{EditorCookie.class};
    }

    @Override
    protected void initialize() {
        super.initialize();
        // see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
        putValue("noIconInMenu", Boolean.TRUE);
    }

    public HelpCtx getHelpCtx() {
        return HelpCtx.DEFAULT_HELP;
    }

    @Override
    protected boolean asynchronous() {
        return false;
    }
}

